<template>
  <div class="comment-item">
    <div class="comment-header">
      <span class="comment-author">{{ comment.user_nickname || '匿名用户' }}</span>
      <span class="comment-time">{{ formatTime(comment.created_at || comment.comment_time) }}</span>
    </div>
    <div class="comment-content">
      {{ comment.content }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'

interface Comment {
  id: number
  user_nickname?: string
  content: string
  created_at?: string
  comment_time?: string
}

defineProps<{
  comment: Comment
}>()

// 格式化时间
const formatTime = (timeString?: string) => {
  if (!timeString) return ''
  const date = new Date(timeString)
  return date.toLocaleString('zh-CN', {
    year: 'numeric',
    month: 'short',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit'
  })
}
</script>

<style scoped>
.comment-item {
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.comment-author {
  font-weight: 500;
  color: #333;
}

.comment-time {
  font-size: 12px;
  color: #999;
}

.comment-content {
  color: #666;
  line-height: 1.5;
}
</style>